﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tsanie.ShellExtension.Util {
    public static class DelegateExtensions {
        public static void SafeRun(this Action action) {
            if (action != null)
                action();
        }
        public static void SafeRun<T>(this Action<T> action, T value) {
            if (action != null)
                action(value);
        }
        public static void SafeRun<T1, T2>(this Action<T1, T2> action, T1 obj1, T2 obj2) {
            if (action != null)
                action(obj1, obj2);
        }
        public static bool SafeRun<T>(this Predicate<T> action, T value) {
            return action.SafeRun(value, false);
        }
        public static bool SafeRun<T>(this Predicate<T> action, T value, bool def) {
            if (action != null)
                return action(value);
            return def;
        }
        public static V SafeRun<T, V>(this Delegate action, T obj) {
            if (action != null)
                return (V)action.DynamicInvoke(new object[] { obj });
            return default(V);
        }
    }
}
